package MediatorMod;

import java.util.HashMap;
import java.util.Map;

public class code {
    interface Mediator {
        void createColleagues();

        void shareInformation(String info, Colleague sender);
    }

    // 抽象同事类
    abstract class Colleague {
        protected Mediator mediator;

        public void setMediator(Mediator mediator) {
            this.mediator = mediator;
        }

        public abstract void shareInformation(String info);
    }

    // 旅行社子系统
    class TravelCompaniesSubsystem extends Colleague {
        @Override
        public void shareInformation(String info) {
            System.out.println("旅行社子系统接收到信息: " + info);
        }
    }

    // 宾馆子系统
    class HotelsSubsystem extends Colleague {
        @Override
        public void shareInformation(String info) {
            System.out.println("宾馆子系统接收到信息: " + info);
        }
    }

    // 餐厅子系统
    class RestaurantsSubsystem extends Colleague {
        @Override
        public void shareInformation(String info) {
            System.out.println("餐厅子系统接收到信息: " + info);
        }
    }

    // 机场子系统
    class AirportSubsystem extends Colleague {
        @Override
        public void shareInformation(String info) {
            System.out.println("机场子系统接收到信息: " + info);
        }
    }

    // 旅游景点子系统
    class TourismAttractionsSubsystem extends Colleague {
        @Override
        public void shareInformation(String info) {
            System.out.println("旅游景点子系统接收到信息: " + info);
        }
    }

    // 旅游综合信息系统
    class Systems implements Mediator {
        Map<String, Colleague> colleagues = new HashMap<>();

        public Systems() {
            colleagues.put("TravelCompaniesSubsystem", new TravelCompaniesSubsystem());
            colleagues.put("HotelsSubsystem", new HotelsSubsystem());
            colleagues.put("RestaurantsSubsystem", new RestaurantsSubsystem());
            colleagues.put("AirportSubsystem", new AirportSubsystem());
            colleagues.put("TourismAttractionsSubsystem", new TourismAttractionsSubsystem());
        }

        @Override
        public void createColleagues() {
            for (Colleague colleague : colleagues.values()) {
                colleague.setMediator(this);
            }
        }

        @Override
        public void shareInformation(String info, Colleague sender) {
            for (Colleague colleague : colleagues.values()) {
                if (colleague != sender) {
                    colleague.shareInformation(info);
                }
            }
        }
    }

}
